#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json

def generate_detailed_report(json_file):
    """生成详细的网站数据报告"""

    # 读取JSON数据
    with open(json_file, 'r', encoding='utf-8') as f:
        data = json.load(f)

    print("=" * 80)
    print("PICKFREE 免费资源导航网站详细数据��告")
    print("=" * 80)

    total_websites = 0
    category_stats = {}

    print("\n分类统计:")
    print("-" * 50)

    for category, websites in data.items():
        count = len(websites)
        total_websites += count
        category_stats[category] = count
        print(f"[分类] {category}")
        print(f"   网站数量: {count} 个")

        # 统计标签
        all_badges = []
        for site in websites:
            all_badges.extend(site.get('badges', []))

        if all_badges:
            badge_counts = {}
            for badge in all_badges:
                badge_counts[badge] = badge_counts.get(badge, 0) + 1

            top_badges = sorted(badge_counts.items(), key=lambda x: x[1], reverse=True)[:5]
            print(f"   热门标签: {', '.join([f'{badge}({count})' for badge, count in top_badges])}")

        print()

    print(f"总计: {total_websites} 个网站，{len(data)} 个分类")
    print("\n" + "=" * 80)

    # 按分类显示所有网站
    print("\n详细网站列表:")
    print("=" * 80)

    for category, websites in data.items():
        print(f"\n[分类] {category} ({len(websites)} 个网站)")
        print("-" * 60)

        for i, site in enumerate(websites, 1):
            print(f"\n{i}. {site['title']}")
            print(f"   网址: {site['url']}")
            print(f"   描述: {site['description']}")
            print(f"   封面: {site['cover_image'].split('/')[-1]}")  # 只显示文件名

            badges = site.get('badges', [])
            if badges:
                print(f"   标签: {', '.join(badges)}")
            else:
                print(f"   标签: 无")

    print("\n" + "=" * 80)
    print("数据分析")
    print("=" * 80)

    # 找出最大的分类
    max_category = max(category_stats.items(), key=lambda x: x[1])
    print(f"最大分类: {max_category[0]} ({max_category[1]} 个网站)")

    # 找出最小的分类
    min_category = min(category_stats.items(), key=lambda x: x[1])
    print(f"最小分类: {min_category[0]} ({min_category[1]} 个网站)")

    # 统计所有标签
    all_badges_global = []
    for websites in data.values():
        for site in websites:
            all_badges_global.extend(site.get('badges', []))

    if all_badges_global:
        print(f"\n全局标签统计 (共 {len(all_badges_global)} 个标签):")
        badge_counts_global = {}
        for badge in all_badges_global:
            badge_counts_global[badge] = badge_counts_global.get(badge, 0) + 1

        # 按出现次数排序
        sorted_badges = sorted(badge_counts_global.items(), key=lambda x: x[1], reverse=True)

        for badge, count in sorted_badges[:10]:  # 显示前10个
            print(f"   {badge}: {count} 次")

    print(f"\n数据提取完成！")
    print(f"   文件位置: {json_file}")
    print(f"   数据大小: {len(json.dumps(data, ensure_ascii=False))} 字符")

if __name__ == "__main__":
    json_file = 'g:/claude-code-repo/design-nav/website_data_complete.json'
    generate_detailed_report(json_file)